<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/15
 * Time: 14:12
 */

include_once '../tools/common.php';
include_once '../tools/DbTools.php';
$is_login = getLoginStatus();
if(!$is_login){
    echo '尚未登入，<a href="../user/loginUi.php">请登入</a>';
    die;
}else{
    $money = $_POST['money'];
    $opp_cardNo = $_POST['opp_cardNo'];

    if(empty($money) || $money<=0){
        echo '存款金额有误！';die;
    }
    if(empty($opp_cardNo)){
        echo '转换卡号有误！';die;
    }
    $opp_cardId = getCardIdByCardNo($opp_cardNo);


    //到这里，说明金额和账号正常

    session_start();
    $userInfo = $_SESSION[$_COOKIE['Token']];

    if($opp_cardId == $userInfo['CardId']){
        echo '不能给本卡转账！';die;
    }

    //采用存钱函数
    $result = transferMoney($userInfo['CardId'],$opp_cardId,$money);

    if($result['status']){
        echo '操作成功<a href="transfer.php">再次转账</a>';
    }else{
        echo '操作失败: '.$result['message'];
    }

}